package today.rocky.boot.security.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Rocky
 * @version 1.0
 * @date 2020/5/12 17:51
 */
@RestController
@RequestMapping("/test")
public class TestController {

	@RequestMapping("/hello")
	public String hello() {
		return "hello,spring security";
	}

	@RequestMapping("/admin")
	@PreAuthorize("hasRole('ROLE_admin')")
	public String admin() {
		return "hello,spring admin";
	}

	@RequestMapping("/user")
	@PreAuthorize("hasRole('ROLE_user')")
	public String user() {
		return "hello,spring user";
	}

	@RequestMapping("/common")
	@PreAuthorize("hasAnyRole('ROLE_user','ROLE_admin')")
	public String common() {
		return "hello,spring community";
	}

}
